using System;
using System.Collections.Generic;
using System.Text;

namespace DataAccess.Base
{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Collections.Generic;
    using DataAccess.Handlers;
    using System.ComponentModel;

    /// <summary>
    /// Clase DAO base para stored procedures que devuelven una tabla (se mapea a un listado de entidades).
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [DataObject(true)]
    public class ProcedureListDAO<T> : ProcedureDAO<T> //where T : new()
    {
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public IList<T> Execute()
        {
            this.PopulateParameters();

            DataTable dt = DataHelper.Current.ExecuteDataTable(this.ProcedureName, this.Parameters);
            
            List<T> values = new List<T>();

            foreach (DataRow r in dt.Rows)
            {
                values.Add((T)r[0]);
            }

            return values;
        }
    }
}
